package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.TFinanceCheckModel;
import com.iris.live.services.data.models.TInsuranceCheckModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by wzy on 2017/5/18.
 */
public interface InsuranceCheckRepository extends JpaRepository<TInsuranceCheckModel, Integer>, JpaSpecificationExecutor<TInsuranceCheckModel> {

    /**
     * 根据导入批次和车架号查找导入的保险数据
     * @param importBatch 导入批次
     * @param vin 车架号
     * @return 返回
     */
    @Query("select insurance from TInsuranceCheckModel insurance where insurance.importBatch = ?1 and insurance.vin = ?2")
    TInsuranceCheckModel findInsuranceByImportBatchAndVin(String importBatch, String vin);

    /**
     * 根据导入批次和导入用户查找导入的保险数据
     * @param importBatch 导入批次
     * @param importUser 导入用户
     * @return 返回
     */
    @Query("select insurance from TInsuranceCheckModel insurance where insurance.importBatch = ?1 and insurance.importUser = ?2")
    List<TInsuranceCheckModel> findInsuranceByImportBatchAndImportUser(String importBatch,String importUser);

    /**
     * 根据导入车架号查找导入的保险数据
     * @param vin 车架号
     * @return 返回
     */
    @Query("select insurance from TInsuranceCheckModel insurance where insurance.vin = ?1")
    TInsuranceCheckModel findInsuranceByVin(String vin);

    /**
     * 根据导入批次和许可查找导入的保险数据
     * @param importBatch 导入批次
     * @param permit 导入用户
     * @return 返回
     */
    @Query("select insurance from TInsuranceCheckModel insurance where insurance.importBatch = ?1 and insurance.permit =?2")
    List<TInsuranceCheckModel> findInsuranceByImportBatchAndPermit(String importBatch, String permit);

}
